#include <stdio.h>
#include <sys/time.h>

#define VERSION "1.0.0"
#define OUT_FILE_EXT ".file"
#define NEXT_FILE_SEP 3

#ifdef _WIN32
#include <windows.h>
#define OUT_FILE_PATH "d:/file"
#else
#include <unistd.h>
#define OUT_FILE_PATH "/opt/file"
#endif

typedef unsigned short int usint;
typedef unsigned char uchar;

void wait();

int main(void)
{
    struct timeval startTime, duration;
    char startTimeStr[20], durationStr[20];
    char outFileName[20];
    FILE *outFile;

    while (1)
    {
        gettimeofday(&startTime, NULL);
        itoa(startTime.tv_sec, startTimeStr, 10);
        sprintf(outFileName, "%s/%s%s", OUT_FILE_PATH, startTimeStr, OUT_FILE_EXT);
        // 开启文件
        outFile = fopen(outFileName, "w");

        // 记录新循环，每三秒创建一个文件
        gettimeofday(&duration, NULL);
        while (duration.tv_sec - startTime.tv_sec <= NEXT_FILE_SEP)
        {
            fprintf(outFile, "%s\n", "83e79b40");
            fprintf(outFile, "%s\n", "88675820");
            fprintf(outFile, "%s\n", "c8e73ea8");
            fprintf(outFile, "%s\n", "c97716c0");
            wait();
            wait();
            wait();

            // refresh time
            gettimeofday(&duration, NULL);
        }
        // 关闭文件
        fclose(outFile);
    }
}

void wait()
{
#ifdef _WIN32
    Sleep(1000);
#else
    sleep(1000);
#endif
}